package gui;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import serial.SerialReaderListener;

@SuppressWarnings("serial")
public class OutputFrame extends JFrame implements SerialReaderListener {
	private JTextArea output;
	private JButton clear;
	
	private final static Font COURIER = new Font("Courier", Font.PLAIN, 12);
	
	public OutputFrame() {
		setTitle("Messages from Robot");
		setSize(600, 600);
		output = new JTextArea();
		output.setFont(COURIER);
		output.setEditable(false);
		output.setBorder(BorderFactory.createTitledBorder("NXT Output"));
		setLayout(new BorderLayout(1, 1));
		add(new JScrollPane(output), BorderLayout.CENTER);
		
		clear = new JButton("Clear output");
		clear.addActionListener(new Clearer());
		JPanel buttonPanel = new JPanel();
		buttonPanel.add(clear);
		add(buttonPanel, BorderLayout.SOUTH);
	}
	
	private class Clearer implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			clear();
		}
	}

	public void stringReceived(String input) {
		output.setText(output.getText() + input);
	}
	
	public void clear() {
		output.setText("");
	}

	public void halted() {
		//stringReceived("[CONNECTION CLOSED]");
	}
}
